package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.dto.TicketProcessUpdateDto;
import com.zzl.bonds.ticket.entity.TicketProcessEntity;
import com.zzl.bonds.ticket.service.TicketProcessService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 票据审批流程表
 *
 * @author wztsl
 * @date 2021-11-30 14:48:47
 */
@RestController
@RequestMapping("ticket/ticketprocess")
@Slf4j
public class TicketProcessController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired

    private TicketProcessService ticketProcessService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询票据审批流程表数据", operationId = "ticket/ticketprocess/list")
    @ApidocReturnPage(genericTypeClass = TicketProcessEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = ticketProcessService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取票据审批流程表数据", operationId = "ticket/ticketprocess/info")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "ticketProcess", valueClass = TicketProcessEntity.class)
    })
    public Result info(@ApidocParam(name = "票据审批流程表id", required = true) @PathVariable("id") Integer id) {
        TicketProcessEntity ticketProcess = ticketProcessService.getById(id);
        return Result.ok().put("ticketProcess", ticketProcess);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改票据审批流程表", operationId = "ticket/ticketprocess/update")
    @ApidocReturnR
    public Result update(@ApidocParam(name = "修改的票据审批流程表对象值", required = true) @RequestBody TicketProcessUpdateDto ticketProcess) {
        try {
            ticketProcessService.updateTicketProcessById(ticketProcess, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除票据审批流程表", operationId = "ticket/ticketprocess/delete")
    @ApidocReturnR
    public Result delete(@ApidocParam(name = "删除的票据审批流程表对象id集合", required = true) @RequestBody Integer[] ids) {
        ticketProcessService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }


}
